#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1010;
const int M = 1e9 + 7;

int n;
ll x[N], y[N], c[N];

using Line = tuple<ll, ll, ll>;
using Point = pair<ll, ll>;

typedef struct {
    Point mid;
    ll w;
} Node;
// key=中垂线, val=每个中点对应的权值
map<Line, vector<Node>> grp;

int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> x[i] >> y[i] >> c[i];
        x[i] *= 2, y[i] *= 2;
    }

    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            int dx = x[j] - x[i], dy = y[j] - y[i];
            ll w = c[i] + c[j];

            Point mid = { (x[i] + x[j]) / 2, (y[i] + y[j]) / 2 };
            ll a, b, c;
            if (dx == 0) {
                // x-xi = 0, 垂直坐标轴
                a = 0, b = 1, c = -mid.second;
            }
            else if (dy == 0) {
                a = 1, b = 0, c = -mid.first;
            }
            else {
                int g = __gcd(dx, dy);
                dx /= g, dy /= g;

                // 保证a>0
                if (dx < 0) dx *= -1, dy *= -1;
                a = dx, b = dy, c = -dx*mid.first-dy*mid.second;
            }

            // i号点和j号点构成的垂直平分线
            Line pb = { a, b, c };

            grp[pb].push_back({mid, w});
        }
    }

    ll res = -1e18;
    for (auto [_, v] : grp) {
        map<Point, ll> filter;
        for (auto nd : v) {
            Point mid = nd.mid;
            if (filter.find(mid) != filter.end()) {
                filter[mid] = max(nd.w, filter[mid]);
            } else {
                filter[mid] = nd.w;
            }
        }
        // 权值最大+次大
        priority_queue<ll> pq;
        for (auto [_k, _v] : filter) 
            pq.push(_v);

        if (pq.size() >= 2) {
            ll temp = pq.top();
            pq.pop();
            temp += pq.top();

            res = max(res, temp);
        }        
    }

    if (res == -1e18)
        res = -1;
    cout << res << endl;
    return 0;
}